package cn.wolfcode.domain;

import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;

import java.util.HashMap;

@Getter
@Setter
public class SystemDictionaryItem {
    //明细id
    private Long id;
    //明细标题
    private String title;
    //明细序号
    private Integer sequence;
    //对应目录主键id
    private SystemDictionary type;
    //对应自己的明细id
    private SystemDictionaryItem parent;

    public String toJSON() {
        HashMap<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("title", title);
        map.put("sequence", sequence);
        if (type != null) {
            map.put("typeId", type.getId());
        }
        if (parent != null) {
            map.put("parentId", parent.getId());
            map.put("parentTitle", parent.getTitle());
        }

        return JSON.toJSONString(map);
    }
}